home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 18 / Silicon_Graphics_hot mix 18.iso / html / vendors / charybda / software / InstallIt2.csh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1998-01-23  |  12.4 KB  |  419 lines

  1. #!/bin/csh -f
  2.  
  3. #   This is an example installation script for HotMix.
  4. #
  5. #   The bulk of the code in this script is aimed at determining the
  6. #   INST_PATH -- the place to install the software (this isn't as
  7. #   easy as it might initially seem!).  The default is to copy to an
  8. #   installation directory in /usr/tmp.  If /usr/tmp doesn't exist,
  9. #   there is not enough disk space, or the user prefers another directory,
  10. #   the script will ask for another directory name.  In this case,
  11. #   the script will read the desired directory name, check its validity,
  12. #   check the available disk space, and if everything is OK, will then
  13. #   do the installation.
  14. #
  15. #   To customize the script, you will need to change these 4 parameters:
  16. #
  17. #       MYAPP = name of the application
  18. #
  19. #       INST_DIR = name of the installation directory
  20. #                  (this is the directory name, not the full path name)
  21. #       CD_PATH = directory path of the location of the software
  22. #                 on the HotMix CD-ROM (it must begin with "$HOTMIXDIR",
  23. #                 which is the mount point for the CD-ROM drive).
  24. #       KBYTES_REQ = required size of the full installation (in Kbytes).
  25. #
  26. #   In this simple example, the installation just involves copying
  27. #   the software to the hard disk, and then launching the application.
  28. #   In other cases, the installation will probably be more complicated,
  29. #   so you'll need to change the code at the end of the script as well.
  30. #   The rest of the script should not require modification.
  31. #
  32. #   All of the InstallIt and RemoveIt scripts should reside in the
  33. #   $CD_PATH directory.
  34. #
  35. #                                                 
  36. #
  37. #                                                 
  38.  
  39.  
  40. set MYAPP=diver
  41. set INST_DIR=charybda
  42. set KBYTES_REQ=1000
  43.  
  44. #
  45. #  Test to see if on the new Indy filesystem or old one.
  46. #
  47.  
  48. set TEST_NEW=`df -k /usr | /usr/bin/awk '{print $7}'`
  49.  
  50. if ( "$TEST_NEW" == "Mounted /" ) then
  51.    set FILE_STRUCTURE=new
  52.  
  53. else
  54.    set FILE_STRUCTURE=old
  55. endif
  56.  
  57.  
  58. #
  59. #  Determine the INST_PATH name.
  60. #
  61. #  First try /usr/tmp;  then if necessary, ask for another directory.
  62. #
  63.  
  64. @ MBYTES_REQ = ($KBYTES_REQ) / 1000
  65.  
  66. if ( $FILE_STRUCTURE == "new" ) then
  67.    set KBYTES_AVAIL=`df -k / | /bin/grep / | /usr/bin/awk '{print $5}'`
  68. else
  69.    set KBYTES_AVAIL=`df -k /usr | /bin/grep /usr | /usr/bin/awk '{print $5}'`
  70. endif
  71.  
  72. if ( -x /usr/tmp/charybda/diver ) then
  73.     echo " "
  74.     echo "It seems the demo is already installed.  Would you like to launch it? (y/n)?  \c"
  75.     set ans3=($<)
  76.     if ( $ans3 == 'y' ) then
  77.         echo "Launching Charybda Diver ...."
  78. if !($?home) then
  79.         if !($?user) then
  80.                 set usermatch = "^[^:]*:[^:]*:`id -u`:"
  81.                 echo "user not set... using $usermatch"
  82.         else
  83.                 set usermatch = "^$user:"
  84.         endif
  85.  
  86.         set newhome = `grep "$usermatch" /etc/passwd | head -1 | cut -d: -f6`
  87.         echo "home directory not set... setting to $newhome"
  88.         set home = "$newhome"
  89. endif
  90.         $TMPFILEDIR/charybda/diver &
  91.         sleep 1
  92.         if ($user == 'root') then
  93.             $HOTMIXDIR/.bin/netscape/netscape.lock $TMPFILEDIR/charybda/diver_demo_instr
  94.         else
  95.             jot -fv $TMPFILEDIR/charybda/diver_demo_instr 
  96.         endif
  97.  
  98.         exit
  99.     else
  100.         echo " "
  101.         echo "Would you like to continue with another install? (y/n)?  \c"
  102.                 set ans3=($<)
  103.                 if ( $ans3 != 'y' ) then
  104.                     echo " "
  105.                     echo "... Bye."
  106.                     sleep 3
  107.                     exit
  108.         else
  109.             echo " "
  110.             echo "Would you like to remove this software before continuing? (y/n)?  \c"
  111.             set ans3=($<)
  112.             if ( $ans3 == 'y' ) then
  113.                 if ( -w /usr/tmp/charybda ) then
  114.                     echo " "
  115.                     echo "Removing /usr/tmp/charybda "
  116.                     rm -rf /usr/tmp/charybda
  117.                 else
  118.                     echo " "
  119.                     echo "Don't have permission! "
  120.                     echo "Continuing with install..."
  121.                 endif
  122.             endif
  123.                 endif
  124.     endif
  125. endif
  126.  
  127. if ( -w /usr/tmp ) then
  128.  
  129.     if ( $KBYTES_AVAIL > $KBYTES_REQ ) then
  130.  
  131.         set INST_PATH=/usr/tmp/$INST_DIR
  132.  
  133.         echo " "
  134.         echo "This demo requires $MBYTES_REQ Mbytes of disk space."
  135.         echo " "
  136.         echo "It will be installed in a directory named $INST_PATH"
  137.         echo "Is this OK (y/n)?  \c"
  138.         set ans=($<)
  139.         if ( $ans != 'y' ) then
  140.             echo " "
  141.             echo "Do you want to install in another directory (y/n)?  \c"
  142.             set ans2=($<)
  143.             if ( $ans2 != 'y' ) then
  144.                 echo " "
  145.                 echo "... Bye."
  146.                 sleep 3
  147.                 exit
  148.             else
  149.                 set INST_PATH=none
  150.             endif
  151.         else
  152.             if ( -d $INST_PATH ) then
  153.                 echo " "
  154.                 echo "It seems the demo is already installed.  Continue anyway (y/n)?  \c"
  155.                 set ans3=($<)
  156.                 if ( $ans3 != 'y' ) then
  157.                     echo " "
  158.                     echo "... Bye."
  159.                     sleep 3
  160.                     exit
  161.                 endif
  162.                 rm -rf $INST_PATH
  163.             endif
  164.         endif
  165.     else
  166.         set INST_PATH=none
  167.     endif
  168. else
  169.     set INST_PATH=none
  170. endif
  171.  
  172. if ( $INST_PATH == "none" ) then
  173.  
  174. #   Read name of installation directory.
  175.  
  176.     echo " "
  177.     echo "This demo requires $MBYTES_REQ Mbytes of disk space."
  178.  
  179.     LOOP1:
  180.  
  181.     unset INSTDIR_FILESYS
  182.  
  183.     echo " "
  184.     echo "Enter the full path name of an existing directory"
  185.     echo "in which to copy the software (or enter 'q' to quit):  \c"
  186.     set ans=($<)
  187.  
  188. #   Check validity of the path name.  If it contains only a "/",
  189. #   this will cause a divide by zero, and fail.
  190.     set TEST1=`echo $ans | cut -f2 -d"/"`
  191.     if ( ! $#TEST1 ) then
  192.             echo " "
  193.             echo "You cannot use directory /.  Please try again."
  194.             goto LOOP1
  195.     endif
  196.  
  197.     if ( $ans == 'q' ) then
  198.         echo " "
  199.         echo "... Bye."
  200.         sleep 3
  201.         exit
  202.     else if ( $#ans == 0 ) then
  203.         echo " "
  204.         echo "Input error.  Please try again."
  205.         goto LOOP1
  206.     else
  207.  
  208. #       Check validity of the path name again.  It must begin with "/".
  209.         set TEST2=`echo $ans | cut -f2 -d"/" -s`
  210.         if ( ! $#TEST2 ) then
  211.                 echo " "
  212.                 echo "The pathname must begin with /.  Please try again."
  213.                 goto LOOP1
  214.         endif
  215.  
  216.         if ( -d $ans ) then
  217.  
  218.             echo " "
  219.             echo "A $INST_DIR directory will be created in $ans."
  220.             echo "Is this OK (y/n)?:  \c"
  221.             set ans2=($<)
  222.             if ( $ans2 != 'y' ) goto LOOP1
  223.  
  224. #           Determine the space available for the filesystem
  225. #           containing the requested directory.
  226. #
  227.  
  228. #                       Check to see if the directory is actually a link or an
  229. #                       nfs mount and do appropriate checks.
  230.  
  231.                         if ( -l $ans ) then
  232.                                 cd $ans
  233.                                 set CDIR=`pwd`
  234.                                 set KBYTES_AVAIL=`df -k $CDIR | /usr/bin/awk '{print $5}'`
  235.                         endif
  236.  
  237.                         touch $ans/hmtest
  238.                         if ( ! -r $ans/hmtest ) then
  239.  
  240.                                 echo "Can not write to $ans, please choose another directory."
  241.                                 goto LOOP1
  242.                         endif
  243.             /bin/rm -f $ans/hmtest
  244.  
  245.  
  246.  
  247. #           First, find all the mounted filesystems.
  248.             set FILESYSTEMS=`df -k | awk '{print $7}' | grep /`
  249.  
  250. #           Now, beginning with the full path name of the
  251. #           requested directory, start stripping off the trailing
  252. #           subdirectory names, and compare this to the existing
  253. #           file system names.  If these match exactly, then we've
  254. #           found the right file system.
  255.  
  256.             set TEST3=`echo $ans | cut -f3 -d"/"`
  257.             if ( ! $#TEST3 ) then
  258.                 set PATH=$ans
  259.             else
  260.                 set PATH=`dirname $ans`
  261.             endif
  262.             LOOP2:
  263.                 foreach FILESYSTEM ($FILESYSTEMS)
  264.  
  265. #                   Don't do the test if $FILESYSTEM == "/"
  266.                     set TEST4=`echo $FILESYSTEM | cut -f2 -d"/"`
  267.                     if ( $#TEST4 != 0 ) then
  268.  
  269.                         if ( $PATH == $FILESYSTEM ) then
  270.                             set INSTDIR_FILESYS=$PATH
  271.                         endif
  272.                     endif
  273.                 end
  274.                 set PATH=`dirname $PATH`
  275.  
  276. #           Continue looping until we've stripped the pathname
  277. #           down to only "/", or until we find the file system.
  278.  
  279.             set LOOPTEST=`echo $PATH | cut -f2 -d"/"`
  280.             if (( $#LOOPTEST != 0 ) && ( ! $?INSTDIR_FILESYS )) goto LOOP2
  281.  
  282.             if ( $?INSTDIR_FILESYS ) then
  283.  
  284. #               Determine the available space
  285.  
  286.                 set KBYTES_AVAIL=`df -k $INSTDIR_FILESYS | /bin/grep $INSTDIR_FILESYS | /usr/bin/awk '{print $5}'`
  287.  
  288.             else
  289.                 if ( $FILE_STRUCTURE == "new" ) then
  290.                   set KBYTES_AVAIL=`df -k / | /bin/grep / | /usr/bin/awk '{print $5}'`
  291.                 else
  292.                 echo " "
  293.                 echo "  ERROR:  Can't determine the amount of available disk"
  294.                 echo "          space for the directory you requested."
  295.                 echo " "
  296.                 echo "          Continue anyway (y/n)?  \c"
  297.                 set ans3=($<)
  298.                 if ( $ans3 == 'y' ) then
  299.                     @ KBYTES_AVAIL = ($KBYTES_REQ) + 1
  300.                 else
  301.                     echo " "
  302.                     echo "... Bye."
  303.                     sleep 3
  304.                     exit
  305.                 endif
  306.             endif
  307.        endif
  308.  
  309.             if ( $KBYTES_AVAIL > $KBYTES_REQ ) then
  310.                 if ( -w $ans ) then
  311.  
  312. #                   Success!!!
  313.  
  314.                     set INST_PATH=$ans/$INST_DIR
  315.                     echo " "
  316.                 else
  317.                     echo " "
  318.  
  319.                     echo "Can't write to directory $ans."
  320.                     echo "Please try again."
  321.                     goto LOOP1
  322.                 endif
  323.             else
  324.                 echo " "
  325.                 echo "Not enough space available."
  326.                 echo "Please try again."
  327.                 goto LOOP1
  328.             endif
  329.         else
  330.             echo " "
  331.             echo "Can't find directory $ans."
  332.             goto LOOP1
  333.         endif
  334.     endif
  335.  
  336.     # Check installation directory.
  337.     if ( -d $INST_PATH ) then
  338.         echo " "
  339.         echo "It seems the demo is already installed.  Continue anyway (y/n)?  \c"
  340.         set ans3=($<)
  341.         if ( $ans3 != 'y' ) then
  342.             echo " "
  343.             echo "... Bye."
  344.             sleep 3
  345.             exit
  346.         endif
  347.  
  348.         rm -rf $INST_PATH
  349.     endif
  350. endif
  351.  
  352. #  Store INST_PATH in a file so it can be communicated to the RemoveIt script.
  353. #
  354. #  First, try to put it in /usr/tmp.  If we can't, then put it in /tmp
  355. #  and in the user's home directory.  If put in /tmp, the file will
  356. #  disappear if the machine is rebooted.  If put in the user's home
  357. #  directory, we won't be able to find it if the user trying to remove
  358. #  the software is not the same as the user who installed it.  Either
  359. #  case isn't very good, but it's the best we can do if we can't write
  360. #  to /usr/tmp.
  361.  
  362. #/bin/rm -f /usr/tmp/HOTMIXPATH_$INST_DIR > /dev/null
  363. #/bin/rm -f /tmp/HOTMIXPATH_$INST_DIR > /dev/null
  364.  
  365. #/bin/rm -f ~/HOTMIXPATH_$INST_DIR > /dev/null
  366.  
  367. #if ( -w /usr/tmp ) then
  368. #    echo "setenv INST_PATH $INST_PATH" > /usr/tmp/HOTMIXPATH_$INST_DIR
  369. #    /bin/chmod 666 /usr/tmp/HOTMIXPATH_$INST_DIR
  370. #else
  371. #    echo "setenv INST_PATH $INST_PATH" > /tmp/HOTMIXPATH_$INST_DIR
  372. #    /bin/chmod 666 /tmp/HOTMIXPATH_$INST_DIR
  373.  
  374. #    echo "setenv INST_PATH $INST_PATH" > ~/HOTMIXPATH_$INST_DIR
  375. #    /bin/chmod 666 ~/HOTMIXPATH_$INST_DIR
  376. #endif
  377.  
  378. #
  379. #-----------------------------------------------------------------------
  380. #
  381. #  Now that we've finally determined INST_PATH, do the installation.
  382. #  In this case, just copy the software and execute the application.
  383.  
  384. echo " "
  385. echo "Installing Diver Demo.  Please wait..."
  386.      mkdir -p $INST_PATH
  387. #     cd $INST_PATH
  388.     cp -r $CD_PATH/charybda/* $INST_PATH
  389. sleep 10
  390. echo " "
  391. echo "Done."
  392. echo " "
  393. echo "To run the demo:" 
  394. echo "Move to the $INST_PATH directory"
  395. echo "and execute $MYAPP."
  396. echo " "
  397. echo " "
  398. echo "You should also view the demo instructions"
  399. echo "in the $INST_PATH directory. "
  400. echo " "
  401. echo "Do you want to run the demo now (y/n)?  \c"
  402. set ans=($<)
  403. if ( $ans == 'y' ) then
  404.     cd $INST_PATH
  405.     ./diver &
  406.     sleep 1
  407.     if ($user == 'root') then
  408.         $HOTMIXDIR/.bin/netscape/netscape.lock ./diver_demo_instr
  409.     else
  410.         jot -fv ./diver_demo_instr
  411.     endif
  412. else
  413.     echo "... Bye."
  414.     sleep 3
  415. endif
  416. echo "Press Enter to exit this window...  \c"
  417. set a = $<
  418.  
  419.